package com.isesol.ime.service;

import com.google.common.base.*;
import com.google.common.collect.*;
import com.isesol.ime.entity.*;
import com.isesol.ime.manager.*;
import org.springframework.stereotype.*;

import javax.annotation.*;
import java.util.*;

/**
 * 机床参数  Service
 */
@Component
public class EventService{

	@Resource
	MessageManager messageManager;

	public List<Event> getEvents(String messageId){

		Message      message       =messageManager.get(Long.valueOf(messageId));
		List<String> paramNameList = Lists.newArrayList();

		Set<MessageParam> msgParams = message.getMsgParams();
		for (MessageParam messageParam : msgParams){
			Param param = messageParam.getParam();
			paramNameList.add(param.getName());
		}
		Event event = new Event();

		event.setEventName(message.getMsgName());
 		event.setOrder(message.getMsgNumber());
		event.setReply(message.isFeedback() ? "1" : "0");
		event.setStore(message.isPreservation() ? "1" : "0");
		event.setEncode(message.isEncrypt() ? "1" : "0");

		event.setEventContent(Joiner.on("|").join(paramNameList));

		List<Event> eventList = Lists.newArrayList();
		eventList.add(event);

		return eventList;

	}

	public List<Data> getSubData(String messageId){

		Message      message       =messageManager.get(Long.valueOf(messageId));
		List<String> paramNameList = Lists.newArrayList();
		Set<MessageParam> msgParams = message.getMsgParams();
		for (MessageParam messageParam : msgParams){
			Param param = messageParam.getParam();
			paramNameList.add(param.getName());
		}

		List<Data> subdataList = Lists.newArrayList();
		Data       data        = new Data();
		data.setType(message.getMsgName());
		data.setSubContent(Joiner.on("|").join(paramNameList));

		subdataList.add(data);


		return subdataList;

	}

}
